<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<%@ taglib uri="/WEB-INF/tlds/att.tld" prefix="att"%>
<html>
<head>
	<meta name="decorator" content="moduleEdit" />
	<link rel="stylesheet" href="${staticPath}/lib/ztree/3.5/css/zTreeStyle/zTreeStyle.css" type="text/css">
	<script src="${staticPath}/lib/ztree/3.5/js/jquery.ztree.all-3.5.js" type="text/javascript"></script>
	<script src="${staticPath}/js/jquery-dialog.js" type="text/javascript"></script>
	 <script type="text/javascript" src="${staticPath}/lib/jquery-autocomplete/1.1/jquery.autocomplete.min.js"></script>
 	<link rel="stylesheet" href="${staticPath}/lib/jquery-autocomplete/1.1/jquery.autocomplete.css" />
 	<script type="text/javascript" src="${staticPath}/js/brand.js"></script>
	<script type="text/javascript">
		$(document).ready(function() { 
			//$("#brandCname").focus();
			$("#brandCateForm").validate({
				rules: {
					 marketYear: {
					 	number: true
					 },
					 levelId:{
						 required:true
					 },
					 brandType:{
						 required:true
					 },
					 status:{
						 required:true
					 }
				 },
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#save").removeAttr("disabled");
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
				
			});
			
			$("#save").click( function () {
				//$("#save").attr("disabled","disabled");
				if($("#cate_cateName").val()=='error'){
					alert("需选择至招商小类 ");
					return ;
				}
				$("#brandCateForm").submit(); 
			});
			
			//选择招商分类
			var opt = {
					idField : "cateNo",
					nameField : "cate_cateName",
					multiple : false,
					service : "selectCMCateDataService",
					title: "招商分类"
				};
			$("#cmCateDialogMultiple").Dialog(opt);
			
			//品牌类型
			$("#brandType").change(function(){
				changeElementByBrandType();
			});
			//自动补全
			 var options={
					 width: 200,
					 highlight: false,
					 multiple: false,
					 scroll: true,
					 max:10,
					 scrollHeight: 300
				};
			 $("#brandCname").autocomplete("${contextPath}/biz/brand/brand/autocompleteBrandName?name=cn",options );
			 $("#brandEname").autocomplete("${contextPath}/biz/brand/brand/autocompleteBrandName?name=en",options );
		
			 $("#endDate").change(function(){
					if ($("#endDate").val() <= $("#startDate").val()) {
						$("#endDate").focus();
						top.$.jBox.tip('截止日期必须大于起始日期,请重新输入!', 'warning');
						return false;
					}
				});
				
				$("#startDate").change(function(){
					if($("#endDate").val()!=null&&$("#endDate").val()!=""){
						if ($("#endDate").val() <= $("#startDate").val()) {
							$("#startDate").focus();
							top.$.jBox.tip('截止日期必须大于起始日期,请重新输入!', 'warning');
							return false;
						}
					}
				});
				
				$("#submit_wokFlow").click(function(){
					//Oosp_Loading('正在提交，请稍等...');
					if($('#cateNo').val().length<6){
						alert("需选择至招商小类");
						return ;
					}
					$('#brandCateForm').attr('action','${contextPath}/biz/brand/brandcate/submit');
					$("#brandCateForm").submit();
				});
		});

		$(function() {
			changeElementByBrandType();
			$("#save").removeAttr("disabled");
			max_tr = $("#hidden_tr").closest("table").find("tr").length - 2;
			var brandReporter =$("#brand_reporter").val();
			if(brandReporter == null || brandReporter.length < 1)
			{
				$("#reporter").val("");
			}
		});
		//添加隐藏域
		function add_hidden(tId,tList) 
		{
			var tr = $(tId).clone();
			var table = $(tId).closest("table");
			//替换所有的hidden，方便spring的form绑定
			var inputs = tr.find("input");
			var selects = tr.find("select");
			
			max_tr++;
			inputs.each(function() {
				this.id = tList + max_tr + this.id;
				this.name = tList+"[" + max_tr + "]" + this.name;
			});
			
			selects.each(function() {
				this.id = tList + max_tr + this.id;
				this.name = tList+"[" + max_tr + "]" + this.name;
			});
			tr.show();
			table.append(tr);
		}
		
		function delete_tr(t,dList) 
		{
			var tr=$(t).closest("tr");
			var id=tr.find("input :first").val();
			if(id!=0){
				var val=$(dList).val();
				if(val==""){
					$(dList).val(id);
				}else{
					$(dList).val(val+","+id);
				}
			}
			tr.remove();
		}
		
		function changeElementByBrandType()
		{
			var value = $("#brandType").val();
			displayDiv(value);
			loadBrandLevelByBrandType(value);			
		}
		
		function displayDiv(value)
		{
			if(value == '2' || value == '0')
			{
				$("#registerDiv").css("display","none"); 
			}else
			{
				$("#registerDiv").css("display","block"); 
			}
		}
	</script>
<style type="text/css">
h4{ border-bottom:1px dotted #ccc; padding-bottom:10px; margin:30px 0 15px; color:#b12028; font-size: 12px;}
.span-required {color: red;}
</style>
</head>
<body>

<div class="Report_f">
           <div class="Report_f_1">
                <div class="Report_f_title_1">品牌准入</div>
                <ul class="nav nav-tabs Report_f_title_2">
                    <li class="active"><a href="#home" data-toggle="tab">基本资料</a></li>
                    <li><a href="#att"  data-toggle="tab">附件上传</a></li> 
                    <li><a href="#workflow" data-toggle="tab">流程审批 </a></li> 
			  		<li><a href="#diagram" data-toggle="tab">流程图</a></li>
                  </ul>
			<!-- Tab panes -->
			 <form:form id="brandCateForm" name="brandCateForm" modelAttribute="brandCate" action="${contextPath}/biz/brand/brandcate/save" method="post" class="form-inline" role="form">
			<div class="tab-content Report_f_title_3">
                  <div class="tab-pane active" id="home">
                         <div class="Report_f_title_4">
                         <tags:message content="${message}"/>
                        
					           	<form:hidden path="id"/>
								<form:hidden path="cateNo"/>
								<form:hidden path="brandId"/>
								<form:hidden path="brand.id"/>
								<form:hidden path="brandNo"/>
								<form:hidden path="brand.brandNo"/>
								<form:hidden path="viceId" />
								<input type="hidden" id="navId" name="navId" value="${navId }"/>
								<input type="hidden" id="hLevel" value="${brandCate.levelId }"/>
								<div class="f_2">
									<div class="form-group col-sm-6">
											<label for="inputtext3" class="col-sm-3 control-label f_4"><span class="span-required">*</span>品牌类型：</label>
											<div class="col-sm-9 f_6">
												<ossp:select dictType="BRAND_TYPE" defaultSelected="1" value="${ brandCate.brandType}" name="brandType" id="brandType" class_="f_5 required"></ossp:select>
											</div>
									</div>
									<div class="form-group col-sm-6">
										<label for="inputtext3" class="col-sm-3 control-label f_4"><span class="span-required">*</span>招商分类:</label>
										<div class="col-sm-9 f_6">
											<div class="input-group">
											<input type="text" class="f_5 required" id="cate_cateName" name="cateName" value="${brandCate.cateName }" placeholder="请选择招商分类" readonly="readonly">
									 		  <span class="input-group-btn">
										        <button class="btn btn-default btn_3" id="cmCateDialogMultiple" type="button">
										        	选择
										        </button>
										      </span>
											</div>
										</div>
									</div>
								</div>
							<div class="f_2">	
							 <div class="form-group col-sm-6">
								<label for="brand.brandCname" class="col-sm-3 control-label f_4"><span class="span-required">*</span>品牌中文名:</label>
								<div class="col-sm-9 f_6">
									<form:input id="brandCname"  path="brand.brandCname" placeholder="请输入品牌中文名" autocomplete="off"  maxlength="150"  class="f_5 required"/>
								</div>
							</div>
							 <div class="form-group col-sm-6">
								<label for="brand.brandEname" class="col-sm-3 control-label f_4">品牌英文名:</label>
								<div class="col-sm-9 f_6">
									<form:input id="brandEname" path="brand.brandEname" placeholder="请输入品牌英文名" maxlength="100"  class="f_5"/>
								</div>
							</div>
						</div>
						<div class="f_2">
							<div class="form-group col-sm-6">
								<label for="attachArea" class="col-sm-3 control-label f_4">品牌归属地:</label>
								<div class="col-sm-9 f_6">
									<form:input id="brand_attachArea" path="attachArea" maxlength="20" class="f_5"/>
								</div>
							</div>
							<div class="form-group col-sm-6">
								<label for="makeArea" class="col-sm-3 control-label f_4">商品产地:</label>
								<div class="col-sm-9 f_6">
									<form:input id="brand_makeArea" path="makeArea" maxlength="20" class="f_5"/>
								</div>
							</div>
						</div>
						 <div class="f_2">
							<div class="form-group col-sm-6">
								<label for="inMarketYear" class="col-sm-3 control-label f_4">品牌进入市场日期:</label>
								<div class="col-sm-9 f_6">
								 <div class="input-group date form_date" data-date="" data-date-format="yyyy-mm-dd" >
									<input id="brand_inMarketYear" readonly="readonly" placeholder="请选择日期" name="inMarketYear" type="text" class="form-control f_13"
										value="<fmt:formatDate value="${brandCate.inMarketYear}" pattern="yyyy-MM-dd"/>"/>
									<span class="input-group-addon f_time"><span class="glyphicon glyphicon-remove"></span></span>
					                 <span class="input-group-addon f_time"><span class="glyphicon glyphicon-calendar"></span></span>
				                 </div>
			                 	</div>
							</div>
							<div class="form-group col-sm-6">
								<label for="marketYear" class="col-sm-3 control-label f_4">品牌市场经营年限:</label>
								<div class="col-sm-9 f_6">
									<form:input id="marketYear" path="marketYear" maxlength="20" class="f_5"/>
								</div>
							</div>
						</div>
						 <div class="f_2">
							<div class="form-group col-sm-6">
								<label for="companyName" class="col-sm-3 control-label f_4">所属公司名称:</label>
								<div class="col-sm-9 f_6">
									<form:input id="brand_companyName" path="companyName" maxlength="150" class="f_5"/>
								</div>
							</div>
							<div class="form-group col-sm-6">
								<label for="company_contacts" class="col-sm-3 control-label f_4">所属公司联系人:</label>
								<div class="col-sm-9 f_6">
									<form:input id="company_contacts" path="companyContacts" maxlength="30" class="f_5"/>
								</div>
							</div>
						</div>
						 <div class="f_2">
							<div class="form-group col-sm-6">
			   					<label for="levelId" class="col-sm-3 control-label f_4"><span class="span-required">*</span>品牌等级:</label>
							    <div class="col-sm-9 f_6">
							    	<form:select path="levelId" id="levelId" class="f_5 required"></form:select>
								</div>
							</div>
							<div class="form-group col-sm-6">
			   					<label for="brand.status" class="col-sm-3 control-label f_4"><span class="span-required">*</span>品牌状态:</label>
							    <div class="col-sm-9 f_6">
							       <ossp:select dictType="brandStatus"  name="status"id="status" defaultSelected="0" value="${brandCate.status }" class_="f_5 required"></ossp:select>
							    </div>
							</div>
					   </div>	
					   <div class="f_2">
							<div class="form-group col-sm-6">
		   					<label for="brand_isTargetBrand" class="col-sm-3 control-label f_4">是否目标战略品牌:</label>
						   <div class="col-sm-9 f_6">
						    	<ossp:radio dictType="YESORNO" defaultChecked="0" value="${brandCate.isTargetBrand }" name="isTargetBrand"id="isTargetBrand"></ossp:radio>
						    </div>
						</div>
						<div class="form-group col-sm-6">
							<label for="reporter" class="col-sm-3 control-label f_4">提报人:</label>
							<div class="col-sm-9 f_6">
								<form:hidden path="reporter"/> 
								<div class="input-group">
								 <input type="text" class="f_5 required" id="brand_reporter" name="reporterName" value="${brandCate.reporterName }" readonly="readonly">
							      <span class="input-group-btn">
							        <button class="btn btn-default btn_3" id="p_userDialogMultiple" data-dialog="dialog" data-multiple='true' data-idField="reporter" data-nameField="brand_reporter" data-authType="USER" type="button">
							        	选择
							        </button>
							      </span>
							    </div>
								</div>
						</div>
					 </div>
					 <div class="f_2">
							 <div class="form-group col-sm-6">
		   					<label for="reporterIdentity" class="col-sm-3 control-label f_4">提报人身份:</label>
						    <div class="col-sm-9 f_6">
						   	  <ossp:radio dictType="brandReporterId" defaultChecked="0" value="${brandCate.reporterIdentity }" name="reporterIdentity"id="reporterIdentity"></ossp:radio>
						    </div>
							</div>
							<div class="form-group col-sm-6">
								<label for="reportDate" class="col-sm-3 control-label f_4">提报日期:</label>
								<div class="col-sm-9 f_6">
								 <div class="input-group date form_date" data-date="" data-date-format="yyyy-mm-dd" >
									<input id="brand_reportDate" placeholder="请输入日期" readonly="readonly" name="reportDate" type="text"  class="form-control f_13"
										value="<fmt:formatDate value="${brandCate.reportDate}" pattern="yyyy-MM-dd"/>"/>
									<span class="input-group-addon f_time"><span class="glyphicon glyphicon-remove"></span></span>
					                 <span class="input-group-addon f_time"><span class="glyphicon glyphicon-calendar"></span></span>
				                 </div>
			                 	</div>
							</div>
					</div>
                  	<div class="f_3">
	                      <div class="form-group col-xs-12">
							<label for="brandSummary" class="col-lb-1 control-label f_10">品牌简介:</label>
							<div class="col-sm-10 col-lb-2 f_6">
								<form:textarea id="brand_brandSummary" path="brandSummary" class="form-control f_11"  maxlength="1000"/>
							</div>
						 </div>
					</div>
					
					<h4>商标注册信息</h4>
					<div class="f_2">
						<div class="form-group col-sm-6">
							<label for="holder" class="col-sm-3 control-label f_4"><span class="span-required">*</span>注册人:</label>
							<div class="col-sm-9 f_6">
								<form:input id="brand_holder" path="holder" placeholder="请输入商标注册人" maxlength="30" class="f_5 required"/>
							</div>
						</div>
						<div class="form-group col-sm-6">
							<label for="brandRegisterNo" class="col-sm-3 control-label f_4"><span class="span-required">*</span>商标注册证号:</label>
							<div class="col-sm-9 f_6">
								<form:input id="brand_brandRegisterNo" placeholder="请输入商标注册证号" path="brandRegisterNo" maxlength="30" class="f_5 required"/>
							</div>
						</div>
				   </div>
					<div class="f_2">
						<div class="form-group col-sm-6">
						<label for="registerArea" class="col-sm-3 control-label f_4"><span class="span-required">*</span>注册地址:</label>
						<div class="col-sm-9 f_6">
							<form:input id="brand_registerArea" path="registerArea"  maxlength="260" class="f_5 required"/>
						</div>
						</div>
					</div>
					<div class="f_2">
						<div class="form-group col-sm-6">
							<label for="brand_registerDate" class="col-sm-3 control-label f_4"><span class="span-required">*</span>起始日期:</label>
							<div class="input-group date form_date" data-date="" data-date-format="yyyy-mm-dd" >
							<input id="startDate" placeholder="起始日期" readonly="readonly" name="registerStartDate" type="text"  class="form-control f_13 required"
								value="<fmt:formatDate value="${brandCate.registerStartDate}" pattern="yyyy-MM-dd"/>"/>
							<span class="input-group-addon f_time"><span class="glyphicon glyphicon-remove"></span></span>
			                <span class="input-group-addon f_time"><span class="glyphicon glyphicon-calendar"></span></span>
		                 	</div>
						</div>
						<div class="form-group col-sm-6">
							<label for="brand_registerDate" class="col-sm-3 control-label f_4"><span class="span-required">*</span>截止日期:</label>
							<div class="input-group date form_date" data-date="" data-date-format="yyyy-mm-dd" >
							<input id="endDate" placeholder="截止日期" readonly="readonly" name="registerEndDate" type="text"  class="form-control f_13 required"
								value="<fmt:formatDate value="${brandCate.registerEndDate}" pattern="yyyy-MM-dd"/>"/>
							<span class="input-group-addon f_time"><span class="glyphicon glyphicon-remove"></span></span>
			                <span class="input-group-addon f_time"><span class="glyphicon glyphicon-calendar"></span></span>
		                	 </div>
						</div>
					</div>
				<div id="registerDiv">
				<h4>市场地位分析</h4>
				<form:hidden path="brandMarket.id"/>
				<form:hidden path="brandMarket.brandCateId"/>
				<div class="f_3">
                      <div class="form-group col-xs-12">
						<label for="brandMarket.advantage" class="col-lb-1 control-label f_10">优势:</label>
						<div class="col-sm-10 col-lb-2 f_6">
							<form:textarea id="brandMarket_advantage" path="brandMarket.advantage" class="form-control f_11"  maxlength="1000"/>
						</div>
					 </div>
				</div>
				<div class="f_3">
                      <div class="form-group col-xs-12">
						<label for="brandMarket.disadvantage" class="col-lb-1 control-label f_10">劣势:</label>
						<div class="col-sm-10 col-lb-2 f_6">
							<form:textarea id="brandMarket_disadvantage" path="brandMarket.disadvantage" class="form-control f_11"  maxlength="1000"/>
						</div>
					 </div>
				</div>
					
					<h4>竞争品牌</h4>
				<!-- 新增明细 -->
					<table class="table table-striped table-hover o-l-table table-bordered" id="table1">
					<thead>
						<tr>
							<th><span class="span-required">*</span>品牌名称</th>
							<th>品牌等级</th>
							<th>
								<button onclick="add_hidden('#hidden_tr','brandCompeteList');"
								type="button" class="btn btn-warning btn_1 pull-right">添&nbsp;加</button>
							</th>
						</tr>
					</thead>
					<tbody>
						<c:forEach items="${brandCate.brandCompeteList}" varStatus="var" var="item">
							<tr>
								<form:hidden path="brandCompeteList[${var.index}].id" />
								<form:hidden path="brandCompeteList[${var.index}].brandCateId"/>
								<td>
									<form:input path="brandCompeteList[${var.index}].brandName"
										maxlength="150" class="f_5 required" />
								</td>
								<td>
								<ossp:select dictType=""  service="selectBrandLevelDataService?levelType=1" value="${item.brandLevel }" name="brandCompeteList[${var.index}].brandLevel"id="brandCompeteList[${var.index}].brandLevel" class_="f_5 required"></ossp:select>
									 
								</td>
							<td>
							<input type="button" onclick="delete_tr(this,'#delCompetedIds')"
									value="删除" class="btn btn-default btn-sm"></input>
							</td>
							</tr>
						</c:forEach>
						<!-- 隐藏行，用于新增明细start -->
						<tr style="display: none" id="hidden_tr">
							<input type="hidden" value="0"
								class="form-control required" name=".id" id=".id"/>
							<input type="hidden" value="${brandCate.id}"
								class="form-control required" name=".brandCateId" id=".brandCateId"/>
							<td>
								<input type="text" maxlength="150" value="" class="f_5 required" name=".brandName" id=".brandName"/>
							</td>
							<td>
							<ossp:select dictType=""  service="selectBrandLevelDataService?levelType=1" value="${item.brandLevel }" name=".brandLevel"id=".brandLevel" class_="f_5 required"></ossp:select>
							</td>
							<td>
							<input type="button" onclick="delete_tr(this,'#delCompetedIds')"
									value="删除" class="btn btn-default btn-sm"/>
							 </td>
						</tr>
						<!-- 隐藏行，用于新增明细end -->
						<input type="hidden" name="delCompetedIds" id="delCompetedIds"/>
					</tbody>
				</table>
				</div>
				<h4></h4>
					<div class="f_12">
						<button type="button" id="submit_wokFlow" class="btn btn-success btn_5 btn_right">提&nbsp;交</button>
<!-- 					    <button type="button" id="save" class="btn btn-success btn_5 btn_right">保&nbsp;存</button> -->
					    <button type="button" class="btn btn-danger btn_5 btn_right" onclick="history.go(-1)">返&nbsp;回</button>
					</div>
     
                   </div>
              </div>
              
              <div class="tab-pane" id="att">
				 <div class="Report_f_title_4"> 
					 <h4>品牌Logo</h4>
						<div class="f_2">
							<div class="form-group col-sm-6">
								<label for="brand_logo" class="col-sm-3 control-label f_4">品牌Logo:</label>
								<div class="col-sm-9 f_6">
									<att:upload modleName="com.maoye.ossp.biz.brand.entity.BrandCate" key="brandLogo" soureBillID="${brandCate.viceId}"></att:upload>
								</div>
							</div>
						</div>		
						<h4>商标注册证</h4>
						<div class="f_2">
						<div class="form-group col-sm-6">
							<label for="brandRegisterNo" class="col-sm-3 control-label f_4">商标注册证电子版:</label>
							<div class="col-sm-9 f_6">
								<att:upload modleName="com.maoye.ossp.biz.brand.entity.BrandCate" key="brandRegister" soureBillID="${brandCate.viceId}"></att:upload>
							</div>
						</div>
					</div>		
				</div>
				</div>
				<!-- --------------------------------------- -->
				<div class="tab-pane" id="workflow"> 
				<form id="brandCateWorkFlowForm" action="${contextPath}/biz/brand/brandcate/submit" method="post">
				<input type="hidden" id='id' name="id" value="${brandCate.id}"  >
				<input type="hidden" id='brandType' name="brandType" value="${brandCate.brandType}"  >
						<c:import url="/WEB-INF/views/bpm/workflow/workFlowInfo_edit.jsp">
							<c:param name="formName" value="com.maoye.ossp.biz.brand.entity.BrandCate" />
							<c:param name="flowKey" value="IBrand" />
							<c:param name="businessId" value="${brandCate.id}"/>
							<c:param name="method" value="${method}"/>
							<c:param name="isStart" value="${isStart}"/>
						</c:import> 
						 <div class="f_12">
					     <button type="submit" id="save" class="btn btn-success btn_5 btn_right">提交</button>
					   </div>
						</form>			
					</div>
				<div class="tab-pane" id="diagram" style="overflow-x:auto;">
					<iframe id="diagram_iframe" scrolling="no" frameborder=0 width="100%">
					</iframe>
				</div>
<!-- 				 <div class="tab-pane" id="contract_hist"> -->
<!-- 				 	<iframe id="versionFrame"   name="versionFrame"   -->
<!-- 													scrolling="no" frameborder="no" width="100%"></iframe> -->
<!-- 				 </div>	 -->
			 <!-- --------------------------------------- -->
		  </div>
		   </form:form>
	</div>	
</div>
<script type="text/javascript">
	$('.form_date').datetimepicker({
        language:  'zh-CN',
        weekStart: 1,
        todayBtn:  1,
		autoclose: 1,
		todayHighlight: 1,
		startView: 2,
		minView: 2,
		forceParse: 0,
		format: 'yyyy-mm-dd',
		pickerPosition: "bottom-left"
    });
	</script>
</body>
</html>